﻿Cn_Guang ={
	init : function(){
		var onLine = Jes.userSess();
		//Jes.setToday('today');
		//Comm.toptip();
		if(!onLine){
			Cn_Guang.offLine();
			Cn_Guang.loginLoad();
		}else{
			Cn_Guang.onLine();
		}
	}
	,onLine : function(){
		Comm.queryhint();
		Cn_Guang.guangSysUser('List1');
		Cn_Index.queryUserInfo(userInfo.userid);
		Jes.show('grxx');
		Jes.show('rightlist');
		Comm.guangAct('offact');
		Cn_Guang.saying();
	}
	,offLine : function(){
				Jes.show('divreglog');
				$.formValidator.initConfig({formid:"zc_form",onerror:function(){}});
				Cn_Guang.guangUser('List1');
				Comm.guangAct('offact');
				Cn_Guang.saying();	
	}
	,loginLoad : function(){
		var ck = Jes.ie('cuniao.email','cuniao.psd','cuniao.repsd');
		Jes.setFormValue('form1',{lemail:ck[0],lpassword:ck[1],repsd:ck[2]});
		if(!Jes.isNull(ck[1]) && ck[2]==1){
			return this.doLogin();
		}else if(!Jes.isNull(ck[0])){
			$('#tab11').removeClass('tabseled').addClass('tabnoseled');
			$('#tab12').removeClass('tabnoseled').addClass('tabseled');
			Jes.hide('tdivs11');
			Jes.show('tdivs12');
			return false;
		}
	}
	,doLogin : function (flag){
		DWRUtil.useLoadingMessage("正在登入中...");
		var param = Jes.getFormValue('form1',0);
		if(param == null) return;
		Jes.doAction("doLogin@CnAction",param.lemail,param.lpassword,1,function(url){
			if(param.repsd!=null){
				Jes.ie({name:'cuniao.email',val:param.lemail,exp:7,path:'/cuniao/'}
				,{name:'cuniao.psd',val:param.lpassword,exp:7,path:'/cuniao/'}
				,{name:'cuniao.repsd',val:1,exp:7,path:'/cuniao/'});
			}
			if(!Jes.userSess(1))return;
			window.location.href="/cuniao/logining.html";
			/*
			if(flag=='-1'){
				if(!Jes.userSess(1))return;
				//window.location.href="/cuniao";
				window.location.href="/cuniao/logining.html";
			}else{
				//alert(Jes.userSess());
				return Jes.userSess();
			}
			*/
		});
	}
	,psdblur: function(){
		$("#password").formValidator({onshow:"请输入密码",onfocus:"密码不能为空",oncorrect:"输入正确"}).inputValidator({min:6,onerror:"密码不能小于六位,请确认"});
	}
	,repsdblur: function(){
		$("#repassword").formValidator({onshow:"请重复输入密码",onfocus:"两次密码必须一致哦",oncorrect:"输入正确"}).inputValidator({min:6,onerror:"重复密码不能为空,请确认"}).compareValidator({desid:"password",operateor:"=",onerror:"2次密码不一致,请确认"});		
	}
	//正在说
	,saying : function(){
		Jes.query('usercom_query_sql@idx',{'isSess':0,isLoad:false},function(data){
			var html=[];
			html.push('<table id="table1" width="100%" border="0" cellspacing="2" cellpadding="0" class="hd_zzfqtb2">');
			for(var i=0;i<data.length;i++){
				var userUrl='',userlogin='',pic='';
				if(data[i].type=='1')userUrl='/cuniao/cuniao/front/person.html?uid='+data[i].id;
				if(data[i].type=='0'){
					userUrl='/cuniao/cuniao/front/indexbus.html?uid='+data[i].id;
					userlogin=' style="color:blue"';
				}
				if(i<5){
					html.push('<tr>');
				}else{
					html.push('<tr style="display:none">');
				}
                html.push('<td width="40" rowspan="2"><a href="'+userUrl+'"><img style="width:50px;height:50px;" src= "'+Jes.getPicPath(data[i].pic)+'"/></a></td>');
               // if(data[i].pic){pic = '<br/><img src="'+Jes.getPicPath(data[i].pic)+'" width="80" height="80" >';}else{pic='';}
                html.push('<td colspan="2"><a href="'+userUrl+'" class="redh" '+userlogin+'>'+data[i].loginid+'：</a><span>' + data[i].content +'</span>'+pic+'</td></tr>');
				if(i<5){
					html.push('<tr>');
				}else{
					html.push('<tr style="display:none">');
				}
				html.push('<td colspan="2">'+data[i].ctime.substr(11,5)+'<td></tr>');
			}
			html.push('</table>');
			Jes.html('usercom',html);
		});
	}
	//系统推荐用户
	,guangSysUser : function(el){
		Jes.doSaveTObject('cn.recomuser',{param:{'userid':userInfo.userid},isLoad:false},function(data) {
			var html= '';
			for(var i=0;i<data.length;i++){
				html += Cn_Guang._guangSysUserHtml(data[i]);
			}
			Jes.html(el,html);
			$('.ScrCont').width(170*data.length*2+'px');
			$('#List1').width(170*data.length+'px');
			$('#List2').width(170*data.length+'px');
			GetObj("List2").innerHTML = GetObj("List1").innerHTML;
		});
	}
	//逛页面 推荐用户
	,guangUser : function(el){
		Jes.doQueryList('guanguser_query_sql@idx',{isLoad:false,'isSess':0},function(data){
			var html ='';
			for(var i=0;i<data.length;i++){
				html += Cn_Guang._guangUserHtml(data[i]);
			}
			Jes.html(el,html);
			$('.ScrCont').width(170*data.length*2+'px');
			$('#List1').width(170*data.length+'px');
			$('#List2').width(170*data.length+'px');
			GetObj("List2").innerHTML = GetObj("List1").innerHTML;
		});
	}
	,_guangSysUserHtml : function(data){
		var html = '',content='';
		if(data.content!=null&&data.content!=''){
			content = '说："' + data.content + '"';
		}else{
			content = '推荐理由:' + data.commend;
		}
		html = '<li><a href="../front/person.html?uid='+data.userid+'" class="picimg"><img title="'+data.loginid+'" src="'+Jes.getPicPath(data.pic)+'"/><span class="p1">'
			+data.loginid+'</span></a><div class="p2">'+ content +'</div></li>';
		return html;		
	}
	//逛逛推荐用户
	,_guangUserHtml : function(data){
		var html = '',sign='';
		Jes.doSync(function() {
			if(data.sign){
				sign=data.sign
			}else if(data.tag){
				var usertag = data.tag;
				Jes.doQueryList('usertag_query_sql@user',{'isSess':0,isLoad:false},function(data){
					for(var i=0;i<data.length;i++){
						if(usertag!=null&&usertag!=''&&usertag.indexOf(','+data[i].tagid + ',')!=-1){
							sign += data[i].tagname;
							sign += ' ';
						}
					}
					sign = '个人标签:'+sign;
				});
			}
			html = '<li><a href="../front/person.html?uid='+data.id+'" class="picimg"><img title="'+data.loginid+'" src="'+Jes.getPicPath(data.pic)+'"/><span class="p1">'
				+data.loginid+'</span></a><div class="p2">'+sign+'</div></li>';
		});
		return html;
	}
}
//大家正在聊
$(function(){
    t=setInterval("show()",3000);
    $("#table1").mouseover(function(){
   		Jes.alert(1);
        clearInterval(t);
    }).mouseout(function(){
    	Jes.alert(2);
        t=setInterval("show()",Math.floor(Math.random()*5+1)*1000);
    })
})
function show(){
      $("#table1 tr:first").hide();
      $("#table1 tr:first").appendTo($("#table1"));
 	  $("#table1 tr:first").hide();
      $("#table1 tr:first").appendTo($("#table1"));
      for(var i=0;i<10;i++){
      	$("#table1 tr").eq(i).show();
      }
}
//图片滚动列表 mengjia 070816
var Speed = 1; //速度(毫秒)
var Space = 5; //每次移动(px)
var PageWidth = 170; //翻页宽度
var fill = 0; //整体移位
var MoveLock = false;
var MoveTimeObj;
var Comp = 0;
var AutoPlayObj;
function GetObj(objName){
	if(document.getElementById){return eval('document.getElementById("'+objName+'")')}else{return eval('document.all.'+objName)}
}
$('#ISL_Cont').scrollLeft = fill;
$('#ISL_Cont').onmouseover = function(){clearInterval(AutoPlayObj);}
$('#ISL_Cont').onmouseout = function(){AutoPlay();}
//AutoPlay();
function AutoPlay(){ //自动滚动
	 clearInterval(AutoPlayObj);
	 AutoPlayObj = setInterval('ISL_GoDown();ISL_StopDown();',3000); //间隔时间
}
function ISL_GoUp(){ //上翻开始
	 if(MoveLock) return;
	 clearInterval(AutoPlayObj);
	 MoveLock = true;
	 MoveTimeObj = setInterval('ISL_ScrUp();',Speed);
}
function ISL_ScrUp(){ //上翻动作
	 if(GetObj('ISL_Cont').scrollLeft <= 0){
	 	GetObj('ISL_Cont').scrollLeft = GetObj('ISL_Cont').scrollLeft + GetObj('List1').offsetWidth
	 }
	 GetObj('ISL_Cont').scrollLeft -= Space ;
}
function ISL_StopUp(){ //上翻停止
	 clearInterval(MoveTimeObj);
	 if(GetObj('ISL_Cont').scrollLeft % PageWidth - fill != 0){
	  Comp = fill - (GetObj('ISL_Cont').scrollLeft % PageWidth);
	  CompScr();
	 }else{
	  MoveLock = false;
	 }
//	 AutoPlay();
}
function ISL_GoDown(){ //下翻
	 clearInterval(MoveTimeObj);
	 if(MoveLock) return;
	 clearInterval(AutoPlayObj);
	 MoveLock = true;
	 ISL_ScrDown();
	 MoveTimeObj = setInterval('ISL_ScrDown()',Speed);
}
function ISL_StopDown(){ //下翻停止
	 clearInterval(MoveTimeObj);
	 if(GetObj('ISL_Cont').scrollLeft % PageWidth - fill != 0 ){
	  Comp = PageWidth - GetObj('ISL_Cont').scrollLeft % PageWidth + fill;
	  CompScr();
	 }else{
	  MoveLock = false;
	 }
}
function ISL_ScrDown(){ //下翻动作
	 if(GetObj('ISL_Cont').scrollLeft >= GetObj('List1').scrollWidth){
	 	GetObj('ISL_Cont').scrollLeft = GetObj('ISL_Cont').scrollLeft - GetObj('List1').scrollWidth;
	 }
	 GetObj('ISL_Cont').scrollLeft += Space ;
}
function CompScr(){
 var num;
 if(Comp == 0){MoveLock = false;return;}
 if(Comp < 0){ //上翻
  if(Comp < -Space){
   Comp += Space;
   num = Space;
  }else{
   num = -Comp;
   Comp = 0;
  }
  GetObj('ISL_Cont').scrollLeft -= num;
  setTimeout('CompScr()',Speed);
 }else{ //下翻
  if(Comp > Space){
   Comp -= Space;
   num = Space;
  }else{
   num = Comp;
   Comp = 0;
  }
  GetObj('ISL_Cont').scrollLeft += num;
  setTimeout('CompScr()',Speed);
 }
}